/*
 * Serhiy Bondarenko
 * Task 2. Arrays - neighbouring numbers
 */
import java.io.*;
import java.util.Scanner;
import java.lang.Math.*;

/**
 * Class MinDistance is for outputting indexes of the first two 
 * elements with minimum distance(minimum value in whole array) 
 * between them  
 * @version 1.2 28 Jan 2013
 * @author Serhiy Bondarenko
 */ 
public final class MinDistance {

public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int lengthOfArray = inputByKeyboard("Enter length of array:", scan);
    int[] arrayOfNumbers = getArray(lengthOfArray, scan);
    int indexOfFirstElement = findMinDistance(arrayOfNumbers, lengthOfArray);
    outputResult(indexOfFirstElement);
    scan.close();
}

private static int inputByKeyboard(String messageBeforeInputting, Scanner scan) {
    System.out.println(messageBeforeInputting);
    String ch = "";
    int chI = 0;
    if ( scan.hasNextLine() ) {
        ch = scan.nextLine();
        chI = Integer.parseInt(ch);        
    }     
    return chI;
}

private static int[] getArray(int lengthOfArray, Scanner scan) {
    int[] array = new int[lengthOfArray];
	
    for (int index = 0; index < lengthOfArray; index++) {
        array[index] = inputByKeyboard("Element with index "+ index + " =", scan);
    }
    return array;
} 

private static int findMinDistance(int[] array, int lengthOfArray) {
    int distance;
    int minimumDistance = Math.abs(array[1] - array[0]);
    int indexForOutputting = 0;
    
    for(int currentIndex = 0; currentIndex <= lengthOfArray-2; currentIndex++) {
        distance = Math.abs(array[currentIndex+1] - array[currentIndex]);
        if (distance < minimumDistance) {
            minimumDistance = distance;
            indexForOutputting = currentIndex;
        }
    }
    return indexForOutputting;
}

private static void outputResult(int index) {
    System.out.println("\nFirst minimum distance is between:\nelement with index " + index 
                                                   + " and element with index "+ (index + 1));	
}
}